package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.VarietySpecType;
import com.fantastic.service.zjs.VarietySpecTypeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/30 18:45
 * @description: 菜品信息表和菜品规格类型表的关联表请求控制器
 */
@RestController
@RequestMapping("/varietySpecType")
public class VarietySpecTypeControllerAdmin {
    @Resource
    private VarietySpecTypeService varietySpecTypeService;

    /**
     * 查询关联表
     *
     * @param varietySpecType
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listVarietySpecType")
    public ResultData listVarietySpecType(VarietySpecType varietySpecType,
                                          @RequestParam(name = "page",
                                                  defaultValue = "1") int pageNum,
                                          @RequestParam(name = "limit", defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<VarietySpecType> varietySpecTypes = varietySpecTypeService.listVarietySpecType(varietySpecType);
        PageInfo<VarietySpecType> pageInfo = new PageInfo<>(varietySpecTypes);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询关联表的数据
     *
     * @param varietyId
     * @param specTypeId
     * @return
     */
    @GetMapping("/getVarietySpecType")
    public ResultData getVarietySpecType(Integer varietyId, Integer specTypeId) {
        return new ResultData(RespStatusInfo.OK, varietySpecTypeService.getVarietySpecType(varietyId, specTypeId));
    }

    /**
     * 添加关联表的数据
     *
     * @param varietySpecType
     * @return
     */
    @PostMapping("/insertVarietySpecType")
    public ResultData insertVarietySpecType(VarietySpecType varietySpecType) {
        return new ResultData(RespStatusInfo.OK, varietySpecTypeService.insertVarietySpecType(varietySpecType));
    }

    /**
     * 批量添加关联表的数据
     *
     * @param varietySpecType
     * @return
     */
    @PostMapping("/addsVarietySpecType")
    public ResultData addsVarietySpecType(@RequestBody ArrayList<VarietySpecType> varietySpecType) {
        return new ResultData(RespStatusInfo.OK, varietySpecTypeService.insertVarietySpecTypes(varietySpecType));
    }

    /**
     * 删除关联表的数据
     *
     * @param varietyId
     * @param specTypeId
     * @return
     */
    @PostMapping("/deleteVarietySpecType")
    public ResultData deleteVarietySpecType(Integer varietyId, Integer specTypeId) {
        return new ResultData(RespStatusInfo.OK, varietySpecTypeService.deleteVarietySpecType(varietyId, specTypeId));
    }

    /**
     * 删除关联表的数据
     *
     * @param varietyId
     * @param specTypeId
     * @return
     */
    @PostMapping("/deletesVarietySpecType")
    public ResultData deletesVarietySpecType(Integer[] varietyId, Integer[] specTypeId) {
        return new ResultData(RespStatusInfo.OK, varietySpecTypeService.deleteVarietySpecTypes(varietyId, specTypeId));
    }

}
